/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	///  ------------------------------------------ 主城 -----------------------------------
	/// module : structs
	/// </summary>
	public class MainCityPOD : IPOD 
    {
        public readonly static Func<MainCityPOD> FACTORY = () => new MainCityPOD();
		public static Func<MainCityPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        ///  所有区域
        /// </summary>
        private List<MainCityRegionPOD> m_regions;
		/// <summary>
        ///  玩家所在区域Cid
        /// </summary>
		public int curRegionCid;
		/// <summary>
        ///  玩家当前坐标		
        /// </summary>
		public Vector3POD curPos;
		
		
        public List<MainCityRegionPOD> regions
        {
            get
            {
                if(m_regions == null)
                {
                    m_regions = new();
                }
                return m_regions;
            }
            private set => m_regions = value;
        }
        public List<MainCityRegionPOD> unsafe_regions
        {
        	get => m_regions;
        	set => m_regions = value;
        }
		
		/*-- constructors --*/
		public MainCityPOD() {}
		public MainCityPOD(List<MainCityRegionPOD> regions, int curRegionCid, Vector3POD curPos) {
			this.m_regions = regions;
			this.curRegionCid = curRegionCid;
			this.curPos = curPos;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_list_pod(m_regions);
            _out.Write_int(curRegionCid);
            _out.Write_pod(curPos);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            m_regions = _in.Read_list_pod<MainCityRegionPOD>(MainCityRegionPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            curRegionCid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            curPos = _in.Read_pod<Vector3POD>(Vector3POD.DynamicFactory);
        }
		
		public MainCityPOD Clone() {
            MainCityPOD o = DynamicFactory();
            if (m_regions != null) {
                o.m_regions = m_regions.ConvertAll(o => o?.Clone());
            }
            o.curRegionCid = curRegionCid;
            if (curPos != null) {
                o.curPos = curPos.Clone();
            }
            return o;
        }
        
        public void Clear() {
            m_regions = default;
            curRegionCid = default;
            curPos = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "MainCityPOD [";
			str += "regions=";
			str += m_regions.ToString<MainCityRegionPOD>();
			str += ", curRegionCid=";
			str += curRegionCid;
			str += ", curPos=";
			str += curPos;
			str += "]";
			return str;
		}
		
	}
}